package com.zikao.article.articleConfig;/**
 * Created by My on 2021-03-13.
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zikao.article.entity.ArticleEntity;
import com.zikao.article.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * @Author: Likaisheng
 * @Description: 为文章模块配置的定时任务，用于处理文章当日浏览和总浏览
 * @Date: Created in 11:41:35 2021-03-13
 * @Modified By:
 */
@Configuration
@EnableScheduling
@Slf4j
public class ArticleSchedulingConfig {

    @Autowired
    private ArticleService articleService;

    /**
     * 每天凌晨00:00:00执行一次
     * 将文章的当日浏览量清空
     */
//    @Scheduled(cron = "0 0 13 * * ?")
    @Scheduled(cron = "0 0 0 * * ?")
    public void handleArticlePv(){
        log.info("定时任务 handleArticlePv 执行");
        UpdateWrapper<ArticleEntity> updateWrapper = new UpdateWrapper<>();
        // 修改语句
        updateWrapper.set("pv",0);

        // 条件
        // ne 不等于
        updateWrapper.ne("pv",0);
        articleService.update(updateWrapper);
    }
}
